package com.bitbank.smartdevice.ui

import android.support.v4.content.ContextCompat
import android.view.View
import com.bitbank.smartdevice.R
import com.bitbank.smartdevice.adapter.MainPagerAdapter
import com.bitbank.smartdevice.ui.base.BaseFragment
import com.qmuiteam.qmui.util.QMUIResHelper
import com.qmuiteam.qmui.widget.QMUITabSegment
import kotlinx.android.synthetic.main.fragment_main.view.*

/**
 *  Date：2018/12/21
 *  Author：xulee
 *  Desc：
 */
class MainFragment : BaseFragment() {

    override fun getLayoutID(): Int = R.layout.fragment_main

    override fun initView(v: View) {
        initTabs(v)
        initPages(v)
    }

    private fun initPages(v: View) {
        v.pager.adapter = MainPagerAdapter(childFragmentManager)
        v.pager.setSwipeable(false)
        v.tabs.setupWithViewPager(v.pager, false)
    }

    private fun initTabs(v: View) {
        val normalColor = QMUIResHelper.getAttrColor(context, R.attr.qmui_config_color_gray_6)
        val selectColor = QMUIResHelper.getAttrColor(context, R.attr.qmui_config_color_blue)
        v.tabs.setDefaultNormalColor(normalColor)
        v.tabs.setDefaultSelectedColor(selectColor)

        val home = QMUITabSegment.Tab(
            ContextCompat.getDrawable(context!!, R.drawable.ic_home_black_24dp),
            ContextCompat.getDrawable(context!!, R.drawable.ic_home_black_24dp),
            getString(R.string.title_home), false
        )

        val mall = QMUITabSegment.Tab(
            ContextCompat.getDrawable(context!!, R.drawable.ic_dashboard_black_24dp),
            ContextCompat.getDrawable(context!!, R.drawable.ic_dashboard_black_24dp),
            getString(R.string.title_mall), false
        )
        val mine = QMUITabSegment.Tab(
            ContextCompat.getDrawable(context!!, R.drawable.ic_notifications_black_24dp),
            ContextCompat.getDrawable(context!!, R.drawable.ic_notifications_black_24dp),
            getString(R.string.title_mine), false
        )
        v.tabs.addTab(home)
            .addTab(mall)
            .addTab(mine)
    }

    override fun canDragBack(): Boolean {
        return false
    }
}